#include <bits/stdc++.h>
using namespace std;
int T,n,a[200005],b[1000005];
int main()
{

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> T;
    for(int e = 1;e <= T;e++)
    {
        cin >> n;
        int maxx = -1,ans = 0;
        for(int i = 1;i <= n;i++)
        {
            cin >> a[i];
            b[a[i]]++;
            maxx = max(maxx,a[i]);
        }
        for(int i = 1;i <= maxx;i++)
        {
            if(b[i] > 1)
            {
                ans += (b[i]-1)*i;
            }
            b[i]=0;
        }
        cout << ans << endl;
    }
    return 0;
}

